<?php
/**
 * 进货车操作
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');

class cartControl extends MobileControl
{
    /**
     * 构造函数
     */
    public function __construct()
    {
        parent::__construct();
        //允许不登录就可以访问的op
        $op_arr = array('ajaxcart', 'add', 'drop');
        $op_str = '';
        $op_str = isset($_GET['op']) ? $_GET['op'] : $_POST['op'];
        if (!in_array($op_str, $op_arr) && !$_SESSION['member_id']) {
            $current_url = request_uri();
            redirect('index.php?act=login&ref_url=' . urlencode($current_url));
        }
        //验证该会员是否禁止购买
        $noallowbuyop_arr = array('step1', 'step2');
        $noallowbuyop_str = '';
        $noallowbuyop_str = isset($_GET['op']) ? $_GET['op'] : $_POST['op'];
        if (in_array($noallowbuyop_str, $noallowbuyop_arr)) {
            $member_model = new memberModel();
            $member_id = intval($_SESSION['member_id']);
            $member_info = $member_model->infoMember(array('member_id' => "{$member_id}"));
            if (empty($member_info) || !$member_info['is_buy']) {
                appMessage('您没有商品购买的权限,如有疑问请联系客服人员');
            }
            unset($member_id);
            unset($member_info);
            unset($member_model);
        }
    }

    /**
     * 进货车首页
     *
     * @param
     * @return
     */
    public function indexOp()
    {
        logic_cart_manageModel::index();
    }

    /**
     * 异步查询进货车
     */
    public function ajaxcartOp()
    {
        logic_cart_manageModel::ajaxcart();
    }

    /**
     * 进货车添加商品
     *
     * @param
     * @return
     */
    public function addOp()
    {
        logic_cart_manageModel::add();
    }

    /**
     * 进货车更新商品数量
     *
     * @param
     * @return
     */
    public function updateOp()
    {
        logic_cart_manageModel::update();
    }

    /**
     * 进货车删除单个商品
     *
     * @param
     * @return
     */
    public function dropOp()
    {
        logic_cart_manageModel::drop();
    }

}
